%
%
%
function [] = TestTriangulate( )
addPath( genpath('../../dependencies/crust/') );
addPath( genpath('../export') );

frames = load('Take0006.mat');
frames = frames.markerData;
frame = frames(1, :);

v = toMatrix(frame);
exportOBJ('face_original1.obj', frame, 0);

[t, tnorm] = MyRobustCrust(v);

%exportOBJ('face_triangulated.obj', frame, t);

xFrame1CSM = load('1stFrameCSM.txt');

missV = findMissingVert(t);
vertexColorList = zeros(80, 3);
for i = 1:size(missV, 2)
    vertexColorList( missV(i), :) = [150, 200, 120];
end % for
exportPLY( 'missFace.ply', v, vertexColorList, 0);

%testVert(v, xFrame1CSM);

end % function TestTriangulate

function [v] = findMissingVert(t)
nM = 1;
for i = 1:80
    missing = 1;
    for k = 1:80
        for j = 1:3
            if ( t(k, j) == i )
                missing = 0;
            end
        end % for
    end % for k
    
    if (missing)
       v(nM) = i;
       nM = nM + 1;
    end % if
end % for
end % function find missing

function [] = testVert(v1, v2)
n1 = size(v1, 1);
n2 = size(v2, 1);
if (n1 ~= n2) error('TestVert: n1 is not equal to n2'); end
n = n1;
for i = 1:n1
    for j = 1:3
        if ( v1(i, j) ~= v2(i, j) )
            errStr = [' i ' int2str(i) ' j ' int2str(j)];
            error(['v1 != v2' errStr]);
        end % if
    end % for
end % for
end % function testCSM

function [maxDelta] = testVertDelta(v1, v2) 
n = size(v1, 1);
for i = 1:n
    for j = 1:3
        if ( v1(i, j) ~= v2(i, j) )
            errStr = [' i ' int2str(i) ' j ' int2str(j)];
            error(['v1 != v2' errStr]);
        end % if
    end % for
end % for
end % function testVertDelta